package com.beiben.statistics.controller;


import com.alibaba.fastjson.JSONObject;
import com.beiben.quality.domain.QaContractSum;
import com.beiben.quality.domain.QaQualityInfo;
import com.beiben.statistics.service.IErrorRateAnalysisService;
import com.beiben.statistics.vo.ErrorRateAnalysisVo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/quality/analysis")
public class ErrorRateAnalysisController extends BaseController {


    @Autowired
    private IErrorRateAnalysisService errorRateAnalysisService;


/***********************************************生产售后阶段问题分析开始****************************************************/

    /**
     * 总资料差错率和平均值
     */
    @PostMapping("/all/rate")
    @ResponseBody
    public Map<String,Object> selectAllRate(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectAllRate(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /**
     * 按车型查差错率和平均值
     */

    @PostMapping("/type/rate")
    @ResponseBody
    public Map<String,Object> selectRateByType(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectRateByType(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /**
     * 按系统查差错率和平均值
     */

    @PostMapping("/system/rate")
    @ResponseBody
    public Map<String,Object> selectRateBySystem(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectRateBySystem(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /**
     * 按组别查差错率
     */

    @PostMapping("/groups/rate/{type}")
    @ResponseBody
    public Map<String,Object> selectRateByGroups(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response,@PathVariable("type") String type){
        Map<String,Object> map = null;
        try {
            errorRateAnalysisVo.setType(type);
            map = errorRateAnalysisService.selectRateByGroups(errorRateAnalysisVo);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /**
     *
     * @param errorRateAnalysisVo
     * @return
     */

    @PostMapping("/group/error/list")
    public TableDataInfo list(ErrorRateAnalysisVo errorRateAnalysisVo){
        startPage();
        List<QaQualityInfo> list = errorRateAnalysisService.selectgroupErrrorrateSumList(errorRateAnalysisVo);
        return getDataTable(list);
    }


/***********************************************生产售后阶段问题分析结束****************************************************/

/***********************************************试制阶段问题分析开始*******************************************************/

    /**
     * 试制问题总差错率
     */

    @PostMapping("/Trial/rate")
    @ResponseBody
    public Map<String,Object> selectTrialAllRate(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectTrialAllRate(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /**
     * 各组别试制问题总体情况
     */
    @PostMapping("/Trial/rate/groups")
    @ResponseBody
    public Map<String,Object> selectAllTrialRateByGroups(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectAllTrialRateByGroups(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /***
     * 各组别试制问题情况-按车型分
     */
    @PostMapping("/Trial/rate/groups/type")
    @ResponseBody
    public Map<String,Object> selectAllTrialRateByGroupsType(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectAllTrialRateByGroupsType(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /***
     * 各系统试制问题总体情况
     */
    @PostMapping("/Trial/rate/system")
    @ResponseBody
    public Map<String,Object> selectAllTrialRateBySystem(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectAllTrialRateBySystem(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }
    /***
     * 各系统试制问题总体情况-按系统分
     */

    @PostMapping("/Trial/rate/system/type")
    @ResponseBody
    public Map<String,Object> selectAllTrialRateBySystemType(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectAllTrialRateBySystemType(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /***
     * 试制问题数-按问题种类分
     */

    @PostMapping("/Trial/rate/question")
    @ResponseBody
    public Map<String,Object> selectAllTrialRateByQuestion(ErrorRateAnalysisVo errorRateAnalysisVo, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map = null;
        try {
            map = errorRateAnalysisService.selectAllTrialRateByQuestion(errorRateAnalysisVo);


        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(map);
        return json;
    }

    /**
     *组别、系统详情
     * @param errorRateAnalysisVo
     * @return
     */

    @PostMapping("/trial/group/detail/list")
    public TableDataInfo detailListByGroup(ErrorRateAnalysisVo errorRateAnalysisVo){
        startPage();
        List<QaQualityInfo> list = errorRateAnalysisService.selectDetailListByGroup(errorRateAnalysisVo);
        return getDataTable(list);
    }



/***********************************************试制阶段问题分析结束*******************************************************/
}
